using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using Manazra.Models.Repository;
using Manazra.Controllers.Filters;
using Manazra.Models;
using Manazra.Helpers;

namespace Manazra.Controllers
{
    [BasePreControllerActionFilter]
    public class AdminController : Controller
    {
        //articles repository
        private ArticleRepository articleRep = new ArticleRepository();
        //blog repository
        private BlogRepository blogRep = new BlogRepository();

        //delete articles admin page
        [Authorize(Roles = "Admins")]
        public ActionResult DeleteArticles()
        {
            //get articles
            var articles = articleRep.GetRecent();
            return View(articles);
        }

        //post method for delete
        [Authorize(Roles = "Admins")]
        public JsonResult DeleteArticle(int id)
        {
            ControllerStatus result = new ControllerStatus(0, "");

            Article article = articleRep.GetById(id);
            if (article == null)
                result.Message = "Article not found";
            else
            {
                articleRep.Delete(article);
                articleRep.Save();
                result.Status = 1;
            }
            return Json(result);
        }

    }
}
